*###########################################################*
* Effects of Settlement into Ethnic Enclaves on Immigrant   *
* Voter Turnout                                             *
* Andersson, Lajevardi, Lindgren, and Oskarsson             *
* Journal: Journal of Politics                              *
* Stata Replication Code                                    *
*###########################################################*

*********************
* BASIC REGRESSIONS *
*********************


///SET DIRECTORY/log-files/set more off

clear all
cd "C:\Userdata\Shared"
set more off

*capture log close
*log using "Logs\Ethnic Enclaves, political participation\log_REG", replace


use "E:\ProjData\Ethnic Enclaves, political participation\use\ind_panel"


///PREPARE CONTROL VARIABLES
*age
label variable age "Age"
gen age2 = age^2
label variable age2  "Age$^2$"

*sex
label variable sex "Man"

*Married: 
gen married = 1 if Civil==2 | Civil ==3 | Civil ==7
replace married =0 if married ==.

label variable married "Married"

///Children or not
gen parent =1 if Barn0_3>0 | Barn4_6>0 | Barn7_10>0 | Barn11_15> 0 | Barn16_17>0
replace parent =0 if parent==.
replace parent =. if Barn0_3==.
label variable parent "Parent"

///Number of kids
gen children = Barn0_3 + Barn4_6 + Barn7_10 + Barn11_15 + Barn16_17
label variable children  "$\#$ of children"

///Education
encode Sun2000niva_old, gen(Sun2000niva_old_dstr)
gen high_educ = 1 if Sun2000niva_old_dstr>4
replace high_educ =0 if high_educ==.
replace high_educ=. if Sun2000niva_old_dstr==.

label variable high_educ  "Highly educated"


///global macro for covariates in all regressions
global cov sex age age2 married parent children high_educ



///INDEPENDET VARIABLE (ENCLAVE VARIABLES): coethnics
*number of coethnics
*drop the person him/herself
replace coethnics = coethnics-1
label variable coethnics  "Coethnics"
egen stdcoethnics = std(coethnics)
label variable stdcoethnics "std number of coethnics \\ (mean =0, std=1)"

*share of population
gen coshare = coethnics/pop
egen stdcoshare = std(coshare)

label variable stdcoshare  "Coethnics/ \\parish inhabitants"

*logs
gen logcoshare = ln(coshare)
gen logcoethnics = ln(coethnics)

label variable logcoshare  "log(Coethnics/ \\parish inhabitants)"
label variable logcoethnics  "log(Coethnics)"


///voted coethnics as share of right to vote 1982
gen voted_coethnics = voted/right
replace voted_coethnics=0 if voted_coethnics==.
egen stdvoted_coethnics = std(voted_coethnics)
label variable voted_coethnics "Share 1982 voters among coethnics \\ with right to vote 82"
label variable stdvoted_coethnics "Std share 1982 voters among coethnics \\ with right to vote 82"

///NOW CREATE A CUMULATIVE DISTRIBUTION BASED ON VOTING COETHNICS
sort voted_coethnics order
gen N = _N
gen CD1 = _n
gen voted_coethnics_alt_cum = CD1/N

///voted 1982 as share of coethnics
gen voted_coethnics2 = voted/coethnics
egen stdvoted_coethnics2 = std(voted_coethnics2)
label variable voted_coethnics2 "Share 1982 voters \\among all coethnics"
label variable stdvoted_coethnics "Std share 1982 voters \\among all coethnics"

///AGAIN, CREATE A CUMULATIVE DISTRIBUTION BASED ON VOTING COETHNICS/POP
sort voted_coethnics2 order
gen CD2 = _n
gen voted_coethnics_cum = CD2/N

*voted 1982 as share of population
gen sharevoted = voted/pop
egen stdsharevoted = std(sharevoted)
label variable stdsharevoted  "coethnics voting in 1982 \\election/parish inhabitants"




///economic/educatinal 
egen stdtreiman = std(treiman)
label variable stdtreiman  "mean occupational status \\among parish coethnics"
gen logtreiman = ln(treiman)

egen stdinc = std(inc)
label variable stdinc  "mean total income \\among parish coethnics"
gen loginc = ln(inc)

gen shareedu = educ/coethnics
egen stdedu = std(shareedu)
label variable stdedu  "share of high edu. \\among parish coethnics"


////OUTCOME VARIABLE!

///voted or not
gen voted_k =0 if k==1
replace voted_k=1 if voted_k==.

label variable voted_k  "voted in local election"

gen voted_r = 0 if r==1
replace voted_r=1 if r==2  | r==4 | r==5
replace voted_r=. if r==3

label variable voted_r  "voted in national election"

*Labels for different types of voting
replace k = 3 if k==4 | k==5

lab def k 1 "no vote",
lab def k 2 "voted: at polling station", add
lab def k 3 "voted: using post", add

lab values k k	

tab k, sort

*share who voted in the parish
gen sharevoted_parish = votedk/rightk
egen stdpartrate = std(sharevoted_parish)

label variable stdpartrate "voter participation rate parish"


///OTHER CONTROLS:
///moving
*Moving variables: 
replace move_out_muni=0 if move_out_muni==.
replace move=0 if move==.
label variable move_out_muni "moved out of municipality arrival year"


///cohort by country fixed effect
egen cohortbycountry = group(IFAUkod im_year)




//////////////////////////////////////////////////////////////////////////////////////
///Baseline reg - NOTE TABLE 2 IS CREATED MANUALLY BY COMBINING "reg" AND "reglong"
////////////////////////////////////////////////////////////////////////////////////

///short run effect

eststo clear

eststo: areg voted_k stdcoshare $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 


 ///LONG TERM RESULTS
 
 preserve
 ///long term: MERGE ON 2010 VOTING DATA
 
rename r r_first
rename k k_first
rename l l_first
 
 
merge 1:m LopNr using "D:\SCB_ConPol\Stata\VD\Valdelt_2010", keepusing (LopNr r k l)
keep if _merge==3


*check for duplicates - OK
*duplicates report LopNr 

///create voting variable

///voted or not
gen voted_k2010 =0 if k==1
replace voted_k2010=1 if voted_k2010==.

label variable voted_k2010  "voted in local election 2010"

///Baseline reg
eststo clear

eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reglong.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 


restore

///////////////////////////////////////////
/// AUXILIARY ANALYSIS  ///////////////////
//////////////////////////////////////////

///ALTERNATIVE MEASURE - TABLE A5

*Like the main table, TABLE A5 is also constructed by combining the long term 
*and the short term tables directly in latex

///using coethnicsvoted/coethnicstrighttovote
eststo clear

eststo: areg voted_k stdcoshare $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_alt_cum<0.25 & voted_coethnics_alt_cum!=., absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_alt_cum>0.25 & voted_coethnics_alt_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_alt_cum>0.50 & voted_coethnics_alt_cum<0.75, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_alt_cum>0.75 & voted_coethnics_alt_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_alt.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 


 ///LONG TERM RESULTS
 
 preserve
 ///long term: MERGE ON 2010 VOTING DATA
 
rename r r_first
rename k k_first
rename l l_first
 
 
merge 1:m LopNr using "D:\SCB_ConPol\Stata\VD\Valdelt_2010", keepusing (LopNr r k l)
keep if _merge==3


*check for duplicates - OK
*duplicates report LopNr 

///create voting variable

///voted or not
gen voted_k2010 =0 if k==1
replace voted_k2010=1 if voted_k2010==.

label variable voted_k2010  "voted in local election 2010"


eststo clear

eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry if voted_coethnics_alt_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry if voted_coethnics_alt_cum>0.25 & voted_coethnics_alt_cum<0.50, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry if voted_coethnics_alt_cum>0.50 & voted_coethnics_alt_cum<0.75, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k2010 stdcoshare $cov i.cohortbycountry if voted_coethnics_alt_cum>0.75 & voted_coethnics_alt_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reglong_alt.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 


restore

////////////////////////////////////
///TABLE A6 - LOGS/SINGLE CONTRY CODES
/// this table combines three separate tables below

*SINGLE COUNTRIES
gen singlecountries = 1 if IFAUkod==30 | IFAUkod==46 | IFAUkod==47 | IFAUkod==48

preserve 
keep if singlecountries==1

eststo clear

eststo: areg voted_k stdcoshare $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_singlecountries.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 

restore 

///FOCUS ON LOGCOETHNICS - FUNCTIONAL FORM

eststo clear

eststo: areg voted_k logcoethnics $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k logcoethnics $cov i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k logcoethnics $cov i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k logcoethnics $cov i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k logcoethnics $cov i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_logs.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(logcoethnics) fragment nomtitles nonotes nolines replace 


///NOW COMBINE: FUNCTIONAL FORM AND SINGLE COUNTRY
preserve 
keep if singlecountries==1

eststo clear

eststo: areg voted_k logcoethnics $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k logcoethnics $cov i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k logcoethnics $cov i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k logcoethnics $cov i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k logcoethnics $cov i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_logandsingle.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(logcoethnics) fragment nomtitles nonotes nolines replace 

restore 


////////////////////////
//TABLE A7 - LONG TERM EU-ELECTIONS
 
///MERGE ON 2009 VOTING DATA 
preserve
merge 1:m LopNr using "D:\SCB_ConPol\Stata\VD\Valdelt_09", keepusing (LopNr e)
keep if _merge==3


*check for duplicates - OK
*duplicates report LopNr 

///create voting variable

///voted or not
gen voted_2009 =0 if e==1
replace voted_2009=1 if voted_2009==.

label variable voted_2009  "voted in EU election 2009"


///Baseline reg
eststo clear

eststo: areg voted_2009 stdcoshare $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_2009 stdcoshare $cov i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_2009 stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_2009 stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_2009 stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reglong_EU.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 

restore




//////////////////////////////////////////////////////////////////////////////////////
///NOW TABLE A8 - ADDING CONTROL FOR MOVING OUT OF MUNICIPALITY

///short run effect

eststo clear

eststo: areg voted_k stdcoshare $cov move_out_muni i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov move_out_muni i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov move_out_muni i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov move_out_muni i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov move_out_muni i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_move.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 


 ///LONG TERM RESULTS
 
 preserve
 ///long term: MERGE ON 2010 VOTING DATA
 
rename r r_first
rename k k_first
rename l l_first
 
 
merge 1:m LopNr using "D:\SCB_ConPol\Stata\VD\Valdelt_2010", keepusing (LopNr r k l)
keep if _merge==3


*check for duplicates - OK
*duplicates report LopNr 

///create voting variable

///voted or not
gen voted_k2010 =0 if k==1
replace voted_k2010=1 if voted_k2010==.

label variable voted_k2010  "voted in local election 2010"

///Baseline reg
eststo clear

eststo: areg voted_k2010 stdcoshare $cov move_out_muni i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k2010 stdcoshare $cov move_out_muni i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k2010 stdcoshare $cov move_out_muni i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k2010 stdcoshare $cov move_out_muni i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k2010 stdcoshare $cov move_out_muni i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reglong_move.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 


restore


 //////////////////////////
///MORE DIAGNOSTICS!
 
/// DO THE SHORT RUN RESULTS USING THE LONG RUN SAMPLE

 preserve
rename r r_first
rename k k_first
rename l l_first

merge 1:m LopNr using "D:\SCB_ConPol\Stata\VD\Valdelt_2010", keepusing (LopNr r k l)
keep if _merge==3

///Baseline reg
eststo clear

eststo: areg voted_k stdcoshare $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare $cov i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\regwithlongsample.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 

restore



///////////////////////////////////
///Short run effect split sample men and women - split sample

eststo clear

eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if sex==1, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum<0.25 & sex==1, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 & sex==1 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 & sex==1 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=. & sex==1, absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_men.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 

eststo clear

eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if sex==0, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum<0.25 & sex==0, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 & sex==0 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 & sex==0 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=. & sex==0, absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_women.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 

file open stats using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\describe\stats.txt", write replace


///Are the effects in the fourth column signf. different from each other?
set matsize 11000

///fit the two models
eststo clear
quietly reg voted_k stdcoshare $cov ib(last).cohortbycountry i.Forsamling if voted_coethnics_cum>0.75 & sex==1
estimates store man

quietly reg voted_k stdcoshare $cov ib(last).cohortbycountry i.Forsamling if voted_coethnics_cum>0.75 & sex==0
estimates store wom

*Common covariance-matrix 
suest man wom, vce(cluster Kommun)

*test
test [man_mean]stdcoshare-[wom_mean]stdcoshare = 0

*save to text
file write stats "P-value Man vs Wom: `r(p)' " 	

///////////////////////////////////
///Short run effect split sample voting for nd in 1991 - split sample

sort votes_nd order
gen CD3 = _n
gen voted_nd_cum = CD3/N

eststo clear

eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_nd_cum>0.5, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum<0.25 & voted_nd_cum>0.5, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 & voted_nd_cum>0.5 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 & voted_nd_cum>0.5 , absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=. & voted_nd_cum>0.5, absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_ndlarge.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 

eststo clear

eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_nd_cum<0.5, absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum<0.25 & voted_nd_cum<0.5, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50 & voted_nd_cum<0.5 , absorb(Forsamling) vce(cluster Kommun)
 
eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75 & voted_nd_cum<0.5, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare sex age age2 married parent children high_educ i.cohortbycountry if voted_coethnics_cum>0.75 & voted_coethnics_cum!=. & voted_nd_cum<0.5, absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_ndsmall.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare) fragment nomtitles nonotes nolines replace 



//////////////////////////
//DIAGNOSTICS

///FIRST PREDICT VOTING
eststo clear

eststo: probit voted_k sex married age age2 parent children high_educ i.cohortbycountry, robust
predict z
egen stdz = std(z)
label variable stdz "std prediction"

///NOW REGRESS SHARE OF COETHNICS ON PREDICTION
eststo: areg coshare stdz, absorb(Forsamling) vce(cluster Kommun)
eststo: areg coshare stdz if voted_coethnics_cum<0.25, absorb(Forsamling) vce(cluster Kommun)
eststo: areg coshare stdz if voted_coethnics_cum>0.25 & voted_coethnics_cum<0.50, absorb(Forsamling) vce(cluster Kommun)
eststo: areg coshare stdz if voted_coethnics_cum>0.50 & voted_coethnics_cum<0.75, absorb(Forsamling) vce(cluster Kommun)
eststo: areg coshare stdz if voted_coethnics_cum>0.75 & voted_coethnics_cum!=., absorb(Forsamling) vce(cluster Kommun)

esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_diagnostics.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(sex age age2 married parent children high_educ stdz) fragment nomtitles nonotes nolines replace 

///////////////////////////////
///Different quality measures
eststo clear

eststo: areg voted_k stdcoshare stdsharevoted  $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)

///socioeconomci measure

eststo: areg voted_k stdcoshare stdsharevoted stdedu $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)

eststo: areg voted_k stdcoshare stdsharevoted stdtreiman stdinc stdedu $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)



esttab using "C:\Users\henrik\Dropbox\Ethnic Enclaves and Voting\Output\reg\reg_q.tex", ///
se nofloat noconstant compress label nonumbers nogaps /// 
keep(stdcoshare stdsharevoted stdtreiman stdinc stdedu) fragment nomtitles nonotes nolines replace 

eststo: areg voted_k stdedu  $cov i.cohortbycountry, absorb(Forsamling) vce(cluster Kommun)



///is the effect of the different estimates significantly different from each other 

///the short run using long run sample 
///baseline results

*Merge on 2010 sample
rename k k_first
merge 1:m LopNr using "D:\SCB_ConPol\Stata\VD\Valdelt_2010", keepusing (LopNr k)
drop if _merge==2

*generate variable to separate samples
gen longsample = 1 if _merge==3


///fit the two models
eststo clear
quietly reg voted_k stdcoshare $cov ib(last).cohortbycountry i.Forsamling if voted_coethnics_cum>0.75 
estimates store b

quietly reg voted_k stdcoshare $cov ib(last).cohortbycountry i.Forsamling if voted_coethnics_cum>0.75 & longsample==1
estimates store c

*Common covariance-matrix 
suest b c, vce(cluster Kommun)

*test
test [b_mean]stdcoshare-[c_mean]stdcoshare = 0

*save to text
file write stats "P-value long vs short sample: `r(p)' " 	

*Add number of obs too
sum LopNr
file write stats "Total obs: `r(N)' " 

file close stats

log close
